import request from '@/utils/request'
import type { ApiResponse, Model, PageResponse, PageParams } from '@/types/api'

export interface ModelQueryParams extends PageParams {
  siteId?: number
  name?: string
  type?: number
}

// 模型管理API
export const modelApi = {
  // 分页查询模型列表
  getModelPage(params: ModelQueryParams): Promise<ApiResponse<PageResponse<Model>>> {
    return request({
      url: '/admin/model/page',
      method: 'get',
      params,
    })
  },

  // 获取模型详情
  getModel(id: number): Promise<ApiResponse<Model>> {
    return request({
      url: `/admin/model/${id}`,
      method: 'get',
    })
  },

  // 创建模型
  createModel(data: Partial<Model>): Promise<ApiResponse<void>> {
    return request({
      url: '/admin/model',
      method: 'post',
      data,
    })
  },

  // 更新模型
  updateModel(id: number, data: Partial<Model>): Promise<ApiResponse<void>> {
    return request({
      url: `/admin/model/${id}`,
      method: 'put',
      data,
    })
  },

  // 删除模型
  deleteModel(id: number): Promise<ApiResponse<void>> {
    return request({
      url: `/admin/model/${id}`,
      method: 'delete',
    })
  },

  // 更新模型状态
  updateModelStatus(id: number, status: number): Promise<ApiResponse<void>> {
    return request({
      url: `/admin/model/${id}/status`,
      method: 'put',
      params: { status },
    })
  },

  // 获取全局模型
  getGlobalModels(type: number): Promise<ApiResponse<Model[]>> {
    return request({
      url: '/admin/model/global',
      method: 'get',
      params: { type },
    })
  },

  // 获取站点模型
  getSiteModels(siteId: number, type: number): Promise<ApiResponse<Model[]>> {
    return request({
      url: '/admin/model/site',
      method: 'get',
      params: { siteId, type },
    })
  },
}
